<?php
namespace Spoof\Controller;
use Common\Controller\SpoofController;
class TestController extends SpoofController {

    public function index(){

        if (IS_POST){

            $setting= C('UPLOAD_SITEIMG_QINIU');
           $Upload = new \Think\Upload($setting);
            $info = $Upload->upload($_FILES);
            var_dump($info);
        }else{
            $this->display('test/index');
        }

    }

    /**
     * 恶搞模板
     */
    public function getimgtemplate(){

        $setting= C('UPLOAD_SITEIMG_QINIU');
        $setting['savePath'] = 'spoof/upload/img';
        var_dump($setting);

    }


    public function getfile()
    {
        echo '1';
        $code = $_FILES['file'];//获取小程序传来的图片
        if (is_uploaded_file($_FILES['file']['tmp_name'])) {
            //把文件转存到你希望的目录（不要使用copy函数）
            $uploaded_file = $_FILES['file']['tmp_name'];

            $setting= C('UPLOAD_SITEIMG_QINIU');

            $Upload = new \Think\Upload($setting);
            $info = $Upload->upload($_FILES);

            //我们给每个用户动态的创建一个文件夹
            $user_path = 'Public/spoof';
            //判断该用户文件夹是否已经有这个文件夹
            if (!file_exists($user_path)) {
                mkdir($user_path);
            }

            $file_true_name = $_FILES['file']['name'];
            $move_to_file = $user_path."/".$file_true_name;

            if (move_uploaded_file($uploaded_file, iconv("utf-8", "gb2312", $move_to_file))) {
                $this->returnData(array('url'=>'http://first123.com/'.$move_to_file));
            } else {
                echo "上传失败" . date("Y-m-d H:i:sa");
            }


        }
    }


    public function uploadimg(){

        if ($_FILES){

            $setting= C('UPLOAD_SITEIMG_QINIU');
            $setting['savePath'] = 'spoof/upload/';
            $Upload = new \Think\Upload($setting);
            $info = $Upload->upload($_FILES);
            $file = $info['file'];
            $data = array(
                'url'=>$file['url'],
                'name'=>$file['name'],
                'type'=>$file['type'],
                'size'=>$file['size'],
                'ext'=>$file['ext'],
                'savename'=>$file['savename'],
                'savepath'=>$file['savepath'],
                'spoof_member_id'=>'1',
            );
            M('spoof_uploadimg')->data($data)->add();
            $this->returnData(array('url'=>$file['url']));
        }



    }


}